<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Submit Score</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f9;
            margin: 0;
            padding: 20px;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        form {
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
            width: 300px;
        }

        h1 {
            color: #333;
            font-size: 24px;
            text-align: center;
        }

        input, button {
            width: 100%;
            padding: 8px;
            margin-top: 10px;
            border-radius: 4px;
            border: 1px solid #ccc;
            box-sizing: border-box; /* Adds padding inside the box */
        }

        button {
            background-color: #0056b3;
            color: white;
            border: none;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        button:hover {
            background-color: #003580;
        }

    </style>
</head>
<body>
<h1>输入你的分数</h1>
<div>
    <form id="scoreForm">
        <label for="name">姓名:</label>
        <input type="text" id="name" placeholder="输入你的姓名">

        <label for="school">学校:</label>
        <input type="text" id="school" placeholder="输入学校">

        <label for="major">专业:</label>
        <input type="text" id="major" placeholder="输入专业">

        <label for="score">成绩:</label>
        <input type="number" id="score" placeholder="输入成绩">

        <button type="button" onclick="submitScore()">提交</button>
    </form>
</div>

<script>
    function submitScore() {
        const data = {
            name: document.getElementById('name').value,
            school: document.getElementById('school').value,
            major: document.getElementById('major').value,
            score: parseInt(document.getElementById('score').value)
        };

        fetch('http://localhost:8087/api/scores/submit', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(data)
        })
            .then(response => response.json())
            .then(data => {
                alert('成绩提交成功!');
                document.getElementById('scoreForm').reset(); // Clear the form after submission
            })
            .catch(error => console.error('Error submitting score:', error));
    }
</script>
</body>
</html>
